# -*- coding: utf-8 -*-

# 更新代码流程

from config.server import InitConfig
from scripts import SSHClient


def run_update_code(update_key=None):
    """
    更新代码
    :param update_key: frontend 前端, backend 后端
    :return:
    """
    host_info = ["hostname", "port", "username", "password"]
    host_dict = {key: getattr(InitConfig.config, key) for key in host_info}

    # 到指定目录 执行命令
    with SSHClient(**host_dict) as ssh_client:
        if update_key is not None:
            # 命令行列表
            command_list = getattr(InitConfig.config, f"{update_key}_command")
            print("command_list", command_list)
            command_str = "; ".join(command_list)
            res = ssh_client.execute_command(command_str)
            print(res, "\n")

